//
//  demandTableViewCell.m
//  BAOASystem
//
//  Created by michael on 2018/3/6.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "demandxqTableViewCell.h"

#import "demandTableViewCell.h"
#import "pdnewsTableViewCell.h"
#import "pdnewsxqTableViewCell.h"

@implementation demandTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setDic:(NSDictionary *)dic{



_dic = dic;
[self initview];

}
- (void)initview{
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
    UIView *view  = [[UIView alloc]initWithFrame:CGRectMake(0, 29, KScreenWidth, 1)];
    view.backgroundColor  = [UIColor colorWithHexString:@"f0eff5"];
    [bgView addSubview:view];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-20, 29)];
label.text = NSLocalizedString(@"采购信息", nil);
label.textColor = [UIColor colorWithHexString:@"484848"];
      [label setFont:[UIFont systemFontOfSize:16]];

   [bgView addSubview:label];
   [self addSubview:bgView];
NSArray *pricearray  =_dic[@"dmdprice"];
NSArray *attributearray  =_dic[@"dmdattribute"];
NSDictionary *dic  =_dic[@"product"];
     CGFloat height = [OAToolBox sizebyText:dic[@"keywords"] font:13 minsWidth:120];
NSDictionary *dic2 = _dic[@"demand"];
     CGFloat height2 = [OAToolBox sizebyText:dic2[@"newRemark"] font:13 minsWidth:80];
     if (height2<32) {
    height2 = 32;
}
if (pricearray.count==0) {
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, KScreenWidth, height2+32+2*32+attributearray.count*32) style:UITableViewStylePlain];

}else{
_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, KScreenWidth, height2+32+1*32+attributearray.count*32+(pricearray.count+1)*32) style:UITableViewStylePlain];

}
_tableview.separatorStyle = NO;
_tableview.backgroundColor = [UIColor whiteColor];
//_tableview.frame = self.frame;
_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{NSArray *pricearray  =_dic[@"dmdprice"];
NSArray *attributearray  =_dic[@"pdattribute"];

if (pricearray.count==0) {
return 4;
}else{

    return 4;

}

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *pricearray  =_dic[@"dmdprice"];
NSArray *attributearray  =_dic[@"dmdattribute"];
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
        if (pricearray.count==0) {
    return 0;
}else{
    return pricearray.count+1;

}
            
        case 2:
            return attributearray.count;
             break;
             case 3:
            return 1;
             break;
        default:
            return 1;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 if (indexPath.section == 0) {
 static NSString *CellIdentifier1 = @"Cellbendititlepic1";

    demandxqTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[demandxqTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;


    }
        NSDictionary *productdic = _dic[@"demand"];
 
cell.dic = productdic;
    return cell;
}else if (indexPath.section ==1){

if (indexPath.row ==0) {
 static NSString *CellIdentifier0 = @"Cellbendititlepic0";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;


    }
       UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
                       label.numberOfLines = 0;

       label.textColor = [UIColor colorWithHexString:@"484848"];
        [label setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label];
           UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
                                  label2.numberOfLines = 0;

       label2.textColor = [UIColor colorWithHexString:@"484848"];
        [label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label2];
        label.text =NSLocalizedString(@"商品详情-订货量(件)", nil);
        label2.text =NSLocalizedString(@"商品详情-价格(元/件)", nil);
    
    return cell;
}else{
 static NSString *CellIdentifier21 = @"Cellbendititlepic21";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier21];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier21];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
       label.textColor = [UIColor colorWithHexString:@"484848"];
        [label setFont:[UIFont systemFontOfSize:13]];
                        label.numberOfLines = 0;

        [cell.contentView addSubview:label];
           UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
       label2.textColor = [UIColor colorWithHexString:@"484848"];
        [label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label2];
        NSArray *array = _dic[@"dmdprice"];
        NSDictionary *dic =array[indexPath.row-1];
        label2.numberOfLines = 0;
        label.text =[NSString stringWithFormat:@"%@-%@",dic[@"startNum"],dic[@"endNum"]];
        label2.text =[NSString stringWithFormat:@"%@",dic[@"price"]];
    
    return cell;
}
}else if (indexPath.section ==2){
 static NSString *CellIdentifier31 = @"Cellbendititlepic31";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier31];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier31];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
       label.textColor = [UIColor colorWithHexString:@"484848"];
        [label setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label];
                label.numberOfLines = 0;

           UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
       label2.textColor = [UIColor colorWithHexString:@"484848"];
        [label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label2];
        NSArray *array = _dic[@"dmdattribute"];
        NSDictionary *dic =array[indexPath.row];
        label2.numberOfLines = 0;
        label.text =[NSString stringWithFormat:@"%@",dic[@"name"]];
        label2.text =[NSString stringWithFormat:@"%@",dic[@"values"]];
    
    return cell;
}else{
 static NSString *CellIdentifier3 = @"Cellbendititlepic3";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3];
    }
NSDictionary *dic = _dic[@"demand"];
     CGFloat height = [OAToolBox sizebyText:dic[@"newRemark"] font:13 minsWidth:80];
     if (height<32) {
    height = 32;
}
  UILabel *label = [[UILabel alloc]init];
label.frame = CGRectMake(0, 0, 80, 32);
label.numberOfLines = 0;
//采购信息-详细介绍
    label.backgroundColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:13];
    label.textColor =[UIColor colorWithHexString:@"a1a1a1"];
label.text = NSLocalizedString(@"采购信息-详细介绍", nil);;
[cell.contentView addSubview:label];
    UILabel *textlabel = [[UILabel alloc]init];
textlabel.frame = CGRectMake(label.right, 0, KScreenWidth-80, height);
textlabel.numberOfLines = 0;
    textlabel.backgroundColor = [UIColor whiteColor];
    textlabel.font = [UIFont systemFontOfSize:13];
    textlabel.textColor =[UIColor colorWithHexString:@"a1a1a1"];
textlabel.text = dic[@"newRemark"];
[cell.contentView addSubview:textlabel];

    return cell;

}

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *pricearray  =_dic[@"dmdprice"];
NSArray *attributearray  =_dic[@"dmdattribute"];
NSDictionary *dic  =_dic[@"product"];
     CGFloat height = [OAToolBox sizebyText:dic[@"keywords"] font:13 minsWidth:120];
     if (height<32) {
    height = 32;
}
height = 32;
if (indexPath.section==0) {
if (pricearray.count ==0) {
//    return 2*32+height;
        return 3*32;

}else{
//    return 1*32+height;
    return 2*32;

    }
}else if(indexPath.section ==1){
   if (pricearray.count==0) {
    return 0;
}else{
    return 32;

}

}else if(indexPath.section ==2){

return 32;
}else{
NSDictionary *dic = _dic[@"demand"];
     CGFloat height = [OAToolBox sizebyText:dic[@"newRemark"] font:13 minsWidth:80];
    if (height<32) {
    height = 32;
}
     return height;
}


}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

